<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学年" prop="year">
        <el-input
          v-model="queryParams.year"
          placeholder="请输入学年"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学期" prop="semester">
        <el-input
          v-model="queryParams.semester"
          placeholder="请输入学期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="教师名称" prop="teacherName">
        <el-input
          v-model="queryParams.teacherName"
          placeholder="请输入教师名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学生名称" prop="studentName">
        <el-input
          v-model="queryParams.studentName"
          placeholder="请输入学生名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评教时间" prop="commentTime">
          <el-date-picker type="datetimerange" v-model="commentTime" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" :style="{width: '100%'}" start-placeholder="开始日期" end-placeholder="结束日期" range-separator="至" clearable></el-date-picker>
        </el-form-item>

      <el-form-item label="班级名称" prop="courseName">
        <el-input
          v-model="queryParams.courseName"
          placeholder="请输入班级名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业名称" prop="deptName">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入专业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班级名称" prop="className">
        <el-input
          v-model="queryParams.className"
          placeholder="请输入班级名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学院名称" prop="collegeName">
        <el-input
          v-model="queryParams.collegeName"
          placeholder="请输入学院名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          @click="handleBegin"
          v-hasPermi="['edu:eva:list']"
        >开始评教</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          @click="handleEnd"
          v-hasPermi="['edu:eva:list']"
        >结束评教</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['edu:eva:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="evaList" @selection-change="handleSelectionChange">
      <el-table-column label="学年" align="center" prop="year" />
      <el-table-column label="学期" align="center" prop="semester" />
      <el-table-column label="教师名称" align="center" prop="teacherName" />
      <el-table-column label="学生名称" align="center" prop="studentName" />
      <el-table-column label="状态" align="center" prop="statusName" />
      <el-table-column label="学院名称" align="center" prop="collegeName" />
      <el-table-column label="专业名称" align="center" prop="deptName" />
      <el-table-column label="课程名称" align="center" prop="courseName" />
      <el-table-column label="班级名称" align="center" prop="className" />
      <el-table-column label="评教时间" align="center" prop="commentTime" width="180">
        <template slot-scope="scope">
          <span>{{scope.row.commentTime }}</span>
        </template>
      </el-table-column>
            <el-table-column label="教学态度-1" align="center" prop="one" >
            <template slot-scope="scope">
          <span>{{scope.row.one==1 ? "优秀" : scope.row.one==2 ? "良好" : scope.row.one==3 ? "一般" :  scope.row.one==4 ? "及格" : "未评教"   }}</span>
        </template>
      </el-table-column>

            <el-table-column label="教学态度-2" align="center" prop="two" >
            <template slot-scope="scope">
          <span>{{scope.row.one==1 ? "优秀" : scope.row.one==2 ? "良好" : scope.row.one==3 ? "一般" :  scope.row.one==4 ? "及格" : "未评教"   }}</span>
        </template>
      </el-table-column>

      <el-table-column label="教学态度-3" align="center" prop="three" >
            <template slot-scope="scope">
          <span>{{scope.row.one==1 ? "优秀" : scope.row.one==2 ? "良好" : scope.row.one==3 ? "一般" :  scope.row.one==4 ? "及格" : "未评教"   }}</span>
        </template>
      </el-table-column>

      <el-table-column label="教学态度-4" align="center" prop="four" >
            <template slot-scope="scope">
          <span>{{scope.row.one==1 ? "优秀" : scope.row.one==2 ? "良好" : scope.row.one==3 ? "一般" :  scope.row.one==4 ? "及格" : "未评教"   }}</span>
        </template>
      </el-table-column>
      <el-table-column label="教学内容-1" align="center" prop="five" >
            <template slot-scope="scope">
          <span>{{scope.row.one==1 ? "优秀" : scope.row.one==2 ? "良好" : scope.row.one==3 ? "一般" :  scope.row.one==4 ? "及格" : "未评教"   }}</span>
        </template>
      </el-table-column>


      
      <el-table-column label="教学内容-2" align="center" prop="six" >
            <template slot-scope="scope">
          <span>{{scope.row.one==1 ? "优秀" : scope.row.one==2 ? "良好" : scope.row.one==3 ? "一般" :  scope.row.one==4 ? "及格" : "未评教"   }}</span>
        </template>
      </el-table-column>
      <el-table-column label="教学方法-1" align="center" prop="seven" >
            <template slot-scope="scope">
          <span>{{scope.row.one==1 ? "优秀" : scope.row.one==2 ? "良好" : scope.row.one==3 ? "一般" :  scope.row.one==4 ? "及格" : "未评教"   }}</span>
        </template>
      </el-table-column>
      <el-table-column label="教学内容-2" align="center" prop="eight" >
            <template slot-scope="scope">
          <span>{{scope.row.one==1 ? "优秀" : scope.row.one==2 ? "良好" : scope.row.one==3 ? "一般" :  scope.row.one==4 ? "及格" : "未评教"   }}</span>
        </template>
      </el-table-column>
      <el-table-column label="教学内容-3" align="center" prop="nine" >
            <template slot-scope="scope">
          <span>{{scope.row.one==1 ? "优秀" : scope.row.one==2 ? "良好" : scope.row.one==3 ? "一般" :  scope.row.one==4 ? "及格" : "未评教"   }}</span>
        </template>
      </el-table-column>
      <el-table-column label="教学内容-4" align="center" prop="ten" >
            <template slot-scope="scope">
          <span>{{scope.row.one==1 ? "优秀" : scope.row.one==2 ? "良好" : scope.row.one==3 ? "一般" :  scope.row.one==4 ? "及格" : "未评教"   }}</span>
        </template>
      </el-table-column>
      <el-table-column label="教学效果-1" align="center" prop="eleven" >
            <template slot-scope="scope">
          <span>{{scope.row.one==1 ? "优秀" : scope.row.one==2 ? "良好" : scope.row.one==3 ? "一般" :  scope.row.one==4 ? "及格" : "未评教"   }}</span>
        </template>
      </el-table-column>
      <el-table-column label="教学效果-2" align="center" prop="twelve" >
            <template slot-scope="scope">
          <span>{{scope.row.one==1 ? "优秀" : scope.row.one==2 ? "良好" : scope.row.one==3 ? "一般" :  scope.row.one==4 ? "及格" : "未评教"   }}</span>
        </template>
      </el-table-column>
      <el-table-column label="教学效果-3" align="center" prop="thirteen" >
            <template slot-scope="scope">
          <span>{{scope.row.one==1 ? "优秀" : scope.row.one==2 ? "良好" : scope.row.one==3 ? "一般" :  scope.row.one==4 ? "及格" : "未评教"   }}</span>
        </template>
      </el-table-column>
      <el-table-column label="评语" align="center" prop="comment" />

      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['edu:eva:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['edu:eva:remove']"
          >删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改评教对话框 -->
    <!-- <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="教师id" prop="teacherId">
          <el-input v-model="form.teacherId" placeholder="请输入教师id" />
        </el-form-item>
        <el-form-item label="教师名称" prop="teacherName">
          <el-input v-model="form.teacherName" placeholder="请输入教师名称" />
        </el-form-item>
        <el-form-item label="学生id" prop="studentId">
          <el-input v-model="form.studentId" placeholder="请输入学生id" />
        </el-form-item>
        <el-form-item label="学生名称" prop="studentName">
          <el-input v-model="form.studentName" placeholder="请输入学生名称" />
        </el-form-item>
        <el-form-item label="
教学态度--1、线下教学时着装整洁，教态自然；授课精神饱满，语言准确、简练、生动、清楚。线上教学时提前上线准备教学，按时上、下课。" prop="one">
          <el-input v-model="form.one" placeholder="请输入
教学态度--1、线下教学时着装整洁，教态自然；授课精神饱满，语言准确、简练、生动、清楚。线上教学时提前上线准备教学，按时上、下课。" />
        </el-form-item>
        <el-form-item label="教学态度--2、实验" prop="two">
          <el-input v-model="form.two" placeholder="请输入教学态度--2、实验" />
        </el-form-item>
        <el-form-item label="教学态度--3、注重实验教学指导，及时解决在实验课中出现的问题。" prop="three">
          <el-input v-model="form.three" placeholder="请输入教学态度--3、注重实验教学指导，及时解决在实验课中出现的问题。" />
        </el-form-item>
        <el-form-item label="教学态度--4、重视检查出勤情况，根据实际情况采取抽查点名等方式；注意维持课堂秩序，教育督促学生遵守课堂纪律。" prop="four">
          <el-input v-model="form.four" placeholder="请输入教学态度--4、重视检查出勤情况，根据实际情况采取抽查点名等方式；注意维持课堂秩序，教育督促学生遵守课堂纪律。" />
        </el-form-item>
        <el-form-item label="教学内容--1、内容实用，任务明确，难易适宜，方案合理，能反映专业要求，紧密联系实际。" prop="five">
          <el-input v-model="form.five" placeholder="请输入教学内容--1、内容实用，任务明确，难易适宜，方案合理，能反映专业要求，紧密联系实际。" />
        </el-form-item>
        <el-form-item label="教学内容--2、教材或实验" prop="six">
          <el-input v-model="form.six" placeholder="请输入教学内容--2、教材或实验" />
        </el-form-item>
        <el-form-item label="教学方法--1、线下教学时示范操作、准确、熟练，步骤清晰。线上教学时不照搬线下课堂模式，有线上资源供学生学习。" prop="seven">
          <el-input v-model="form.seven" placeholder="请输入教学方法--1、线下教学时示范操作、准确、熟练，步骤清晰。线上教学时不照搬线下课堂模式，有线上资源供学生学习。" />
        </el-form-item>
        <el-form-item label="教学方法--2、实际联系理论，激发学生兴趣，启发学生思维，注重技能培养。" prop="eight">
          <el-input v-model="form.eight" placeholder="请输入教学方法--2、实际联系理论，激发学生兴趣，启发学生思维，注重技能培养。" />
        </el-form-item>
        <el-form-item label="教学方法--3、讲演结合，时间分配合理，突出训练环节" prop="nine">
          <el-input v-model="form.nine" placeholder="请输入教学方法--3、讲演结合，时间分配合理，突出训练环节" />
        </el-form-item>
        <el-form-item label="教学方法--4、预留充足操作时间，教师认真巡视，及时指导" prop="ten">
          <el-input v-model="form.ten" placeholder="请输入教学方法--4、预留充足操作时间，教师认真巡视，及时指导" />
        </el-form-item>
        <el-form-item label="教学效果--1、完成实验实训任务，熟练掌握课程所用软件" prop="eleven">
          <el-input v-model="form.eleven" placeholder="请输入教学效果--1、完成实验实训任务，熟练掌握课程所用软件" />
        </el-form-item>
        <el-form-item label="教学效果--2、独立动手" prop="twelve">
          <el-input v-model="form.twelve" placeholder="请输入教学效果--2、独立动手" />
        </el-form-item>
        <el-form-item label="教学效果--3、线下教学时学生积极主动参与率高，反馈及时，能用专业知识分析并解决实际案例及问题。线上教学时注重学生学习效果，课堂互动多，随时关注学生反馈的问题。" prop="thirteen">
          <el-input v-model="form.thirteen" placeholder="请输入教学效果--3、线下教学时学生积极主动参与率高，反馈及时，能用专业知识分析并解决实际案例及问题。线上教学时注重学生学习效果，课堂互动多，随时关注学生反馈的问题。" />
        </el-form-item>
        <el-form-item label="评语" prop="comment">
          <el-input v-model="form.comment" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="评教时间" prop="commentTime">
          <el-date-picker clearable
            v-model="form.commentTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择评教时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="学年" prop="year">
          <el-input v-model="form.year" placeholder="请输入学年" />
        </el-form-item>
        <el-form-item label="学期(1-上半学期，2-下半学期)" prop="semester">
          <el-input v-model="form.semester" placeholder="请输入学期(1-上半学期，2-下半学期)" />
        </el-form-item>
        <el-form-item label="班级id" prop="courseId">
          <el-input v-model="form.courseId" placeholder="请输入班级id" />
        </el-form-item>
        <el-form-item label="班级名称" prop="courseName">
          <el-input v-model="form.courseName" placeholder="请输入班级名称" />
        </el-form-item>
        <el-form-item label="0代表存在、2代表删除" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入0代表存在、2代表删除" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="专业id" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入专业id" />
        </el-form-item>
        <el-form-item label="专业名称" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入专业名称" />
        </el-form-item>
        <el-form-item label="班级id" prop="classId">
          <el-input v-model="form.classId" placeholder="请输入班级id" />
        </el-form-item>
        <el-form-item label="班级名称" prop="className">
          <el-input v-model="form.className" placeholder="请输入班级名称" />
        </el-form-item>
        <el-form-item label="学院id" prop="collegeId">
          <el-input v-model="form.collegeId" placeholder="请输入学院id" />
        </el-form-item>
        <el-form-item label="学院名称" prop="collegeName">
          <el-input v-model="form.collegeName" placeholder="请输入学院名称" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
import { listEva, getEva, delEva, addEva, updateEva,begin,end } from "@/api/edu/eva";

export default {
  name: "Eva",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 评教表格数据
      evaList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        commentStartTime:null,
        commentStopTime:null,
        teacherId: null,
        teacherName: null,
        studentId: null,
        studentName: null,
        comment: null,
        commentTime: null,
        year: null,
        status: null,
        semester: null,
        courseId: null,
        courseName: null,
        deptId: null,
        deptName: null,
        classId: null,
        className: null,
        collegeId: null,
        collegeName: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      commentTime:null,
      year:null,
      semester:null
    };
  },
  created() {
    this.getList();
    this.getCurrentYear()
  },
  methods: {
    /** 查询评教列表 */
    getList() {
      this.loading = true;
      listEva(this.queryParams).then(response => {
        this.evaList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        teaEvaId: null,
        teacherId: null,
        teacherName: null,
        studentId: null,
        studentName: null,
        one: null,
        two: null,
        three: null,
        four: null,
        five: null,
        six: null,
        seven: null,
        eight: null,
        nine: null,
        ten: null,
        eleven: null,
        twelve: null,
        thirteen: null,
        comment: null,
        commentTime: null,
        year: null,
        status: null,
        semester: null,
        courseId: null,
        courseName: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        deptId: null,
        deptName: null,
        classId: null,
        className: null,
        collegeId: null,
        collegeName: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      console.log(this.commentTime)
      if(this.commentTime){
        this.queryParams.commentStartTime = this.commentTime[0]
        this.queryParams.commentStopTime = this.commentTime[1]
      }else{
        this.queryParams.commentStartTime = null
        this.queryParams.commentStopTime = null
      }
      this.getList();
    },
    //获取当前的年份和学期
    getCurrentYear () {
      this.getConfigKey("edu.current.year.semester").then(response => {
        console.log(response)
        let yearSemester = response.msg
        let yearSemesterArr = yearSemester.split("-")
        this.year = Number(yearSemesterArr[0]);
        this.semester = Number(yearSemesterArr[1]);
        this.queryParams.year = Number(yearSemesterArr[0]);
        this.queryParams.semester = Number(yearSemesterArr[1]);
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.commentTime = null
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.teaEvaId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleBegin(){
      this.$modal.confirm('确认是否开始'+this.year+'-'+this.semester+'学期的评教').then(function() {
        console.log("*******确认")
        begin().then(res =>{
        this.$modal.msgSuccess("提交成功,请等待数据同步完成");
      })
         }).then(() => {
            console.log("*******确认")
         }).catch(() => {
          console.log("*******取消")
         }); 
         this.getList()
    },
    handleEnd(){
      this.$modal.confirm('确认是否结束'+this.year+'-'+this.semester+'学期的评教').then(function() {
        console.log("*******确认")
        end().then(res =>{
          this.$modal.msgSuccess("评教结束成功");
      })
         }).then(() => {
            console.log("*******确认")
         }).catch(() => {
          console.log("*******取消")
         }); 
    }
    // /** 新增按钮操作 */
    // handleAdd() {
    //   this.reset();
    //   this.open = true;
    //   this.title = "添加评教";
    // },
    // /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const teaEvaId = row.teaEvaId || this.ids
    //   getEva(teaEvaId).then(response => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改评教";
    //   });
    // },
//     /** 提交按钮 */
//     submitForm() {
//       this.$refs["form"].validate(valid => {
//         if (valid) {
//           if (this.form.teaEvaId != null) {
//             updateEva(this.form).then(response => {
//               this.$modal.msgSuccess("修改成功");
//               this.open = false;
//               this.getList();
//             });
//           } else {
//             addEva(this.form).then(response => {
//               this.$modal.msgSuccess("新增成功");
//               this.open = false;
//               this.getList();
//             });
//           }
//         }
//       });
//     },
//     /** 删除按钮操作 */
//     handleDelete(row) {
//       const 
// teaEvaIds = row.
// teaEvaId || this.ids;
//       this.$modal.confirm('是否确认删除评教编号为"' + 
// teaEvaIds + '"的数据项？').then(function() {
//         return delEva(
// teaEvaIds);
//       }).then(() => {
//         this.getList();
//         this.$modal.msgSuccess("删除成功");
//       }).catch(() => {});
//     },
    /** 导出按钮操作 */
    ,
    handleExport() {
      this.download('edu/eva/export', {
        ...this.queryParams
      }, `eva_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
